﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using IHISCETeim.BLL;
using System.Threading;
using IHISCETeim.Library;
namespace IHISCETeim.Web
{
    public class Global : System.Web.HttpApplication
    {
        protected static string SyncUClaimDemage = "SyncUClaimDemage";
        private DateTime starttime; 

        protected void Application_Start(object sender, EventArgs e)
        {
            Application[SyncUClaimDemage] = "";
            //Application["StartTime"] = "";
            //Application["runtime"] = "";
        }

        protected void Session_Start(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 清除缓存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Application_BeginRequest(object sender, EventArgs e)
        {           

            if (Application[SyncUClaimDemage].ToString()!=DateTime.Today.ToShortDateString())
            {
                Application[SyncUClaimDemage] = DateTime.Today.ToShortDateString();
              //  SyncSAPController.SyncUClaimDemage();
               // SyncSAPController.SyncAgentList();
               // SyncSAPController.SyncOITMList();
               // SyncSAPController.SyncUpdateInWillDate();
                BaseController.DC.Clear();
            }
            //Application["StartTime"] = System.DateTime.Now;
            starttime = DateTime.Now;

            //处理登录超时时的提示
            //HttpApplication application = (HttpApplication)sender;
            //HttpContext context = application.Context;
            //// context.Response.Write("context.Request.IsAuthenticated" + context.Request.IsAuthenticated.ToString());
            //if (!context.Request.IsAuthenticated && context.Request.Path.ToLower() != FormsAuthentication.LoginUrl.ToLower())
            //{
            //    //HttpContext.Current.Response.Write(context.Request.Path);
            //    //HttpContext.Current.Response.Write(FormsAuthentication.LoginUrl);
            //    string RedirectURLJS = "<script>alert('{0}');top.location.href='{1}';</script>";
            //    RedirectURLJS = string.Format(RedirectURLJS, "请重新登录", FormsAuthentication.LoginUrl);
            //    HttpContext.Current.Response.Write(RedirectURLJS);
            //}
        }

        protected void Application_EndRequest(Object sender, EventArgs e)
        {
           // System.DateTime startTime = (System.DateTime)Application["StartTime"];
           // System.DateTime endTime = System.DateTime.Now;
           // System.TimeSpan ts = endTime - startTime;
           //// Application["runtime"] = (Convert.ToDouble((ts.Milliseconds)) / 1000);
           // Application["runtime"] = ts.Milliseconds;

            DateTime endtime = DateTime.Now;
            HttpApplication application = (HttpApplication)sender;
            HttpContext context = application.Context;
           // HttpBrowserCapabilities b = context.Request.Browser;
            //浏览器信息:
           // string bInfo ="名称：" + b.Browser + ".版本：" + b.Version + ".操作平台：" + b.Platform + ".是否支持COOKIES：" + b.Cookies;


           // SLogController.SPageExecTime_Add(context.Request.Url.ToString(), bInfo, starttime, endtime, context.Request.UserHostAddress + "[" + OUserController.CurrentUser.RealName + "]"+context.Request.UrlReferrer);

        }

        protected void Application_AuthenticateRequest(object sender, EventArgs e)
        {
           
        }

        protected void Application_Error(object sender, EventArgs e)
        {

        }

        protected void Session_End(object sender, EventArgs e)
        {

        }

        protected void Application_End(object sender, EventArgs e)
        {
            BaseController.DC.Clear();
        }

        
            
    }
}